import QtQuick
import QtQuick.Controls

import "." as QML

Rectangle{
    id:popup

    width: 300
    height: 100
    x:Global.showPos.x
    y:Global.showPos.y
    z:5

    border.color: "red"
    border.width: 2

    visible: false

    ListModel{
        id:list
        /*  数据结构
            {报错的单元，错误内容}
            {name(string),data(string)}
        */
    }

    ListView {
        id: view
        width: 300
        height: 50
        focus: true  // 弹出时获得焦点
        visible: true

        model:list

        // 弹出窗口的内部内容
        delegate:ItemDelegate{

            Rectangle {
                anchors.fill: parent
                color: "red"
                anchors.margins: 10

                width: 200
                height:50

                // 这里可以添加你需要的任何UI组件
                Text {
                    text: model.name +":\n" + model.data
                    anchors.centerIn: parent
                    font.pixelSize: 18
                }
            }
        }

        function closePopup(){
            popup.focus = false
            popup.visible = false

            list.clear()
        }

        function openPopup(){
            popup.focus = true
            popup.visible = true
        }
    }

    // 弹出窗口的按钮，用于关闭窗口
    Button {
        text: "关闭"
        anchors.top: view.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked: view.closePopup()

    }


    function appendToHead(pos,what){
        list.insert(0,{name:pos,data:what})

        view.openPopup()
    }



}

